package com.yq.light.note.code.controller;

import com.yq.light.commons.code.entity.CommonResult;
import com.yq.light.commons.code.entity.KnowledgeDb;
import com.yq.light.commons.code.entity.Note;
import com.yq.light.note.code.service.NoteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@Controller
@RequestMapping("/note")
@Slf4j
public class NoteController {

    @Autowired
    private NoteService noteService;

    @RequestMapping("/newNote")
    @ResponseBody
    public CommonResult newNote(@RequestBody Note note){
        log.info("note --"+note);
        int result = 0;
        try{
            result = noteService.newNote(note);
            if(result > 0){
                return new CommonResult(200,"获取数据成功",result);
            }
        }catch (Exception e){
            log.error("DataController -dataList -error --"+e.toString());
        }
        return new CommonResult(200,"获取数据失败",result);
    }

    @RequestMapping("/fetchNoteList")
    @ResponseBody
    public CommonResult fetchNoteList(@RequestParam("ownerAccount") String ownerAccount){
        log.info("ownerAccount --"+ownerAccount);
        try{
            List<Note> list = noteService.fetchNoteList(ownerAccount);
            if(list != null){
                return new CommonResult(200,"获取数据成功",list);
            }
        }catch (Exception e){
            log.error("DataController -dataList -error --"+e.toString());
        }
        return new CommonResult(200,"获取数据失败",null);
    }

}
